//
//  NetWorkRequestModel.m
//  singleTarget
//
//  Created by   李小云 on 17/9/20.
//  Copyright © 2017年   李小云. All rights reserved.
//

#import "NetWorkRequestModel.h"

@implementation NetWorkRequestModel


-(instancetype)init
{
    if (self = [super init]) {
        
        _isJsonRequetFormat = YES;
        _isNSDataReponseFormat = NO;
    }
    
    return self;
    
}

/**
 *  初始化请求模型
 *
 *  @param method       请求方式,字符串如@"get" , @"post"
 *  @param url          请求url
 *  @param parms        请求模型参数,传字典
 *  @param successBlock 成功的回调
 *  @param failBlock    失败的回调
 *
 *  @return NetWorkRequestModel 模型对象
 */
-(instancetype)initWithMethod:(NSString *)method
                          url:(NSString *)url
                        parms:(NSDictionary *)parms
                 successBlock:(NetWorkSuccessRequest)successBlock
                    failBlock:(NetWorkFailRequest)failBlock
{
    
    return [self initWithMethod:method url:url parms:parms cachesType:CachesNone cachesBlock:nil successBlock:successBlock failBlock:failBlock];
    
}

/**
 *  初始化请求模型
 *
 *  @param method       请求方式,字符串如@"get" , @"post"
 *  @param url          请求url
 *  @param parms        请求模型参数,传字典
 *  @param cachesType   缓存方式
 *  @param cachesBlock  缓存的回调
 *  @param successBlock 成功的回调
 *  @param failBlock    失败的回调
 *
 *  @return NetWorkRequestModel 模型对象
 */
-(instancetype)initWithMethod:(NSString *)method
                          url:(NSString *)url
                        parms:(NSDictionary *)parms
                   cachesType:(NetWorkCachesType)type
                  cachesBlock:(NetWorkCachesRequest)cachesBlock
                 successBlock:(NetWorkSuccessRequest)successBlock
                    failBlock:(NetWorkFailRequest)failBlock
{
    
    if (self = [super init]) {
        
        _requestType = [self requestTypeByMethod:method];
        _url = url;
        _parms = parms;
        _cachesBlock = cachesBlock;
        _CachesType = type;
        _successRequestBlock = successBlock;
        _FailRequestBlock = failBlock;
        
    }
    return self;
    
}

- (NSInteger)requestTypeByMethod:(NSString *)method
{
    if ([method isKindOfClass:[NSString class]]) {
        if ([[method lowercaseString] isEqualToString:@"get"]) {
            return NetWorkRequestGet;
        }else if ([[method lowercaseString] isEqualToString:@"post"])
        {
            return NetWorkRequestPost;
        }
    }
    
    return NetWorkRequestGet;
}

@end
